package com.itheima.controller;


import com.itheima.entity.Result;
import com.itheima.pojo.Blog;
import com.itheima.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 归档
 *
 * @author chenzhi
 * @date 2020年8月8日
 */
@RestController
@RequestMapping("/sort")
@CrossOrigin(allowCredentials="true", allowedHeaders="*", methods={RequestMethod.GET,RequestMethod.POST}, origins="*")
@Slf4j
public class WebSortController {

    @Autowired
    private BlogService blogService;

    //归档
    @GetMapping("/getSortList")
    public Result getSortList() {
        log.info("获取归档日期");
        Set<String> monthSet = blogService.getBlogTimeSortList();
        return new Result("success", monthSet);
    }


    @GetMapping("/getArticleByMonth")
    public Result getArticleByMonth(@RequestParam(name = "monthDate", required = false) String monthDate) {
        log.info("通过月份获取文章列表");
        List<Blog> blogList = blogService.getArticleByMonth(monthDate);
        return new Result("success",blogList);
    }


}
